﻿//=====================================================================================================
// LocalizationLibrary
// The Localization Library is a collection of reusable software components that provide 
// support for localization. This library enables you to localize WPF, Silverlight and WP7 applications.
// (http://localizationlibrary.codeplex.com)
//=====================================================================================================
// Author: Nicola Gallo (Website: www.nicola.gallo.name, Email: nicolagmt@hotmail.it) 
//=====================================================================================================

namespace SLS.ExClassLib.Loc
{
    //.NET References
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// Defines all the application's available languages.
    /// </summary>
    public static class Languages
    {
        //Fields

        private static Object _syncRoot = new Object();

        //Constructors

        /// <summary>
        /// Default static constructor.
        /// </summary>
        static Languages()
        {
            LanguagesProvider languagesProvider = LocalizationManager.AppLanguagesProvider ?? new LanguagesProvider();
            AvailableLanguages = languagesProvider.GetAvailableLanguages();
        }

        //Properties

        /// <summary>
        /// Gets all the available languages.
        /// </summary>
        public static Language[] AvailableLanguages { get; private set; }

        //Methods

        /// <summary>
        /// Returns the Language object for a given language code or description.
        /// </summary>
        /// <param name="strLang">The language code or description</param>
        /// <returns>The corresponding Language object</returns>
        public static Language FromString(string strLang)
        {
            Language language = null;
            lock (Languages._syncRoot)
            {
                language = AvailableLanguages.Where(lang => lang.Code == strLang || lang.Description == strLang).FirstOrDefault();
            }
            return language;
        }
    }
}